//
//  LTcountryCodeSelcectController.m
//  LTIM
//
//  Created by 俊松何 on 2017/4/18.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTcountryCodeSelcectController.h"
#import "MMCountry.h"
@interface LTcountryCodeSelcectController ()


@property(nonatomic,strong) NSMutableArray *dataArray;


@end

@implementation LTcountryCodeSelcectController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = NSLTLocalizedString(@"login.selectCode", nil);
    
    self.tableView.rowHeight = 40;
    _dataArray = [NSMutableArray arrayWithCapacity:10];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [UIView new];
    [[MTVerCodeApiManager manager] getCountryCodesWithCompletion:^(NSMutableArray<MMCountry *> *codes, MTError *mterror) {
        if (mterror == nil)
        {
            self.dataArray = codes;
            [self.tableView reloadData];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}




#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
    }
    MMCountry *model = self.dataArray[indexPath.row];
    cell.textLabel.text = model.name;
    cell.textLabel.textColor = [UIColor darkTextColor];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    
//    cell.
    
    cell.detailTextLabel.text = model.dialCode;
    
    cell.backgroundColor = [UIColor whiteColor];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
     MMCountry *model = self.dataArray[indexPath.row];
    if(self.phoneblock)
    {
        self.phoneblock(model.name,model.dialCode);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
}

@end
